class Account {
  constructor(id, user_id, name, type, balance, currency, is_active, created_at, updated_at) {
    this.id = id;
    this.user_id = user_id;
    this.name = name;
    this.type = type;
    this.balance = parseFloat(balance) || 0.00;
    this.currency = currency || 'CNY';
    this.is_active = is_active !== undefined ? is_active : true;
    this.created_at = created_at;
    this.updated_at = updated_at;
  }

  // Create an Account instance from a database row
  static fromRow(row) {
    return new Account(
      row.id,
      row.user_id,
      row.name,
      row.type,
      row.balance,
      row.currency,
      row.is_active,
      row.created_at,
      row.updated_at
    );
  }

  // Convert Account instance to JSON
  toJSON() {
    return {
      id: this.id,
      user_id: this.user_id,
      name: this.name,
      type: this.type,
      balance: this.balance,
      currency: this.currency,
      is_active: this.is_active,
      created_at: this.created_at,
      updated_at: this.updated_at
    };
  }
}

module.exports = Account;